package com.moqbus.core.handler;

import com.moqbus.core.common.constant.Keys;
import com.moqbus.core.session.Session;
import com.moqbus.core.session.SessionManager;
import com.moqbus.core.session.Session.PROT_TYPE;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame;

public class WsBinaryFrameHandler extends SimpleChannelInboundHandler<BinaryWebSocketFrame> {

	@Override
	protected void channelRead0(ChannelHandlerContext ctx, BinaryWebSocketFrame msg) throws Exception {
		
		Session session = SessionManager.findBySessionId(ctx.channel().attr(Keys.SESSION_ID_KEY).get());
		session.setProtType(PROT_TYPE.WS_BIN);
		
		ctx.fireChannelRead(msg.content());
	}

}
